<?php

	include("common.php");
	
	$result = mysql_query("SELECT * FROM `197_links`");
	$links = array();
	while($row = mysql_fetch_assoc($result)){
		array_push($links, $row);
	}
	
?>
<?php include("header.php"); ?>
<h1>修改／刪除連結</h1>
<div id="delete-link-dialog">
	<p>確定刪除？</p>
</div>
<script type="text/javascript" defer="defer">
	$("#delete-link-dialog").dialog({
		width: 300,
		height: 210,
		autoOpen: false,
		title: "刪除連結",
		modal: true,
		draggable: false,
		resizable: false
	});
	function showConfirm(link_id){
		$("#delete-link-dialog").dialog("option", "buttons", {"確定": function(){ $(this).dialog("close"); deleteLink(link_id); }, "取消": function(){ $(this).dialog("close"); }
		}).dialog("open");
	}
	function deleteLink(link_id){
		$("#delete-link-dialog").dialog("option", "buttons", { "關閉": function(){ location.reload(); } });
		$("#delete-link-dialog").html("<img src='../images/ajax-loader.gif' />");
		$("#delete-link-dialog").dialog("open");
		$("#delete-link-dialog").load("linkDelete.php?link_id=" + link_id + "&ajax=true");
	}
</script>
<?php if(empty($links)){ ?>
	<p>目前沒有連結。</p>
<?php } else { ?>
	<ul>
		<?php foreach($links as $row){ ?>
		<li><?php echo $row['title']; ?> - [ <a href="linkEdit.php?link_id=<?php echo $row['link_id']; ?>">編輯</a>｜<a href="linkDelete.php?link_id=<?php echo $row['link_id']; ?>" onclick="showConfirm('<?php echo $row['link_id']; ?>'); return false;">刪除</a> ]</li>
		<?php } ?>
	</ul>
<?php } ?>
<p><a href="linkAdd.php">新增</a></p>
<?php include("sidebar.php"); ?>
<?php include("footer.php"); ?>